<template>
    <div>
        <h3>房号添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房号号码</td>
                    <td><input type="text" v-model="Info.HouseNumName"></td>
                </tr>
                <tr>
                    <td align="right">房型名称</td>
                    <td>
                        <select v-model="Info.HouseTypeName">
                            <option value="">请选择</option>
                            <option :value="item.HouseTypeName" v-for="item in data">{{ item.HouseTypeName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">房价</td>
                    <td><input type="text" v-model="Info.HousePrice"></td>
                </tr>
                <tr>
                    <td align="right">房间数量</td>
                    <td><input type="text" v-model="Info.Housemany"></td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td><input type="radio" name="state" :value="1" v-model="Info.State">启用
                        <input type="radio" name="state" :value="0" v-model="Info.State">禁止
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add" class="btn btn-primary">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
import { idText } from 'typescript';
import router from '@/router';
const Route = useRoute();
const Router = useRouter();

let Info:any=reactive({
    "HouseNumName": "",
    "HouseTypeName": "",
    "HousePrice": '',
    "Housemany": '',
    "State": 1,
})
let data:any=ref([])
onMounted(()=>{
    getlist();
})
const getlist=()=>{
    axios({
        url:'/api/House/GetHouseTypeList',
        method:'get',
        
    })
    .then((res)=>{
        console.log(res);
        data.value=res.data;
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
const add=()=>{
    if(Info.HouseNumName=="")
    {
        alert("房号不能为空");
        return;
    }
    axios({
        url:'/api/House/AddHouseNum',
        method:'post',
        data:Info
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1)
        {
            alert("房号已存在");
            return;
        }
        else if(res.data>0)
        {
            alert("添加成功");
            router.push('/housenumlist');
        }
        else{
            alert("添加失败");
            return;
        }
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>